<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>供应商报关报检业务管理-已受理</title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript" src="<s:url value="../js/ajaxutil.js"/>"></script>
</head>
<script type="text/javascript">
    var bstate = "${param.declaraState }";
    var businessType = [["审核通过", "DS02"], ["已申报", "DS04"],
        ["海关查货", "DS09"], ["海关放行", "DS10"],
        ["商检放行", "DS11"], ["已完成", "DS05"]];
    var formSetting = {
        title: "查询报关报检业务信息",
        module: 'query',
        columns: [{
            name: "businessId",
            label: "业务编号"
        }, {
            name: "state",
            type: "dropdown",
            data: businessType,
            op: "eq",
            label: "业务状态",
            // 			type:"dropdown",
            // 			dropdownType:"ajax",
            // 			url:"../base/dropdown-declarationState",
            // 			op:"eq",
            // 			minLength:0
        }, {
            name: "container_no",
            label: "集装箱号"
        }, {
            name: "contract_no",
            label: "合同协议号"
        }, {
            name: "confirmTime",
            label: "业务提交时间从",
            type: "date",
            op: "ge"
        }, {
            name: "confirmTime",
            label: "到",
            type: "date",
            op: "le"
        }, {
            name: "company_name",
            label: "经营单位"
            // 			type:"dropdown",
            // 			dropdownType:"ajax",
            // 			url:"companyqp-findCompanyByCode?tdateaa=" + timeNum(),
            // 			op:"eq",
            // 			minLength:0
        }, {
            name: "shipper.company",
            label: "实际托运人"
        }],
        buttons: {
            custom: [
                // 				{
                // 					id : "updatebtn-1",
                // 					value : "业务流转",
                // 					click : function() {
                // 						var id = $("#declarationsDataGrid").jqGrid("getGridParam",
                // 						"selrow");
                // 						if(id) {
                // 							var ret = $("#declarationsDataGrid").jqGrid('getRowData',id);
                // 							var iddata = "id=" + ret.id;
                // 							$.ajax({
                // 								cache: false,
                // 								url : "declaration-checkValidatePass",
                // 								dataType : "json",
                // 								data : iddata,
                // 								success : function(data) {
                // 									if($.parseJSON(data.msg).state==1) {
                // 										jw.confirm("确定要该业务进行流转?",function(){
                // 											jw.dialog({iframe:'bizFlow-supChoiceList?sup_type=D&id='+id,width:500, height:200});
                // 										},
                // 										function(){return;});
                // 									}
                // 									else if($.parseJSON(data.msg).state==0) {
                // 										jw.alert("只有处于审核状态的业务才可以进行业务流转操作。");
                // 									}
                // 									else {
                // 										jw.alert($.parseJSON(data.msg).msg);
                // 									}
                // 								}
                // 							});
                // 						} else {
                // 							jw.alert("请点击需要操作的数据!");
                // 						}
                // 					}
                // 				},
                {
                    id: "updatebtn0",
                    value: "查看详细",
                    click: function () {
                        /* var id = $("#declarationsDataGrid").jqGrid("getGridParam",
                         "selrow");
                         if(id) {
                         window.location.href="declaration-findForSupToValidate?id="+id;
                         } else {
                         jw.alert("请点击需要操作的数据!");
                         } */
                        var selectedRowId = $("#declarationsDataGrid")
                                .getGridParam("selrow");
                        if (selectedRowId) {
                            var selectedRow = $("#declarationsDataGrid")
                                    .getRowData(selectedRowId);
                            if (selectedRow.state == "草稿状态") {
                                location.href = "business-updateSingle?id="
                                                + selectedRow.id + "&singleType=D";
                            } else {
                                ajaxLoader
                                        .ajaxPost(
                                                '../datalock/onUnlock?opaId=VDBS&bidId='
                                                + selectedRow.id,
                                                {},
                                                function (data) {
                                                    if (!data) {
                                                        jw.alert(data.errmsg);
                                                    }
                                                    if ("200" == data.errcode) {
                                                        location.href = "business-updateSingle?id="
                                                                        + selectedRow.id
                                                                        + "&singleType=D&identification=list";
                                                    } else {
                                                        jw.alert(data.errmsg);
                                                    }
                                                });
                            }
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "exportExcel",
                    value: "导出数据",
                    click: function () {
                        var businessId = $("#form_in_control_1").val();
                        var state = bstate.substr(0, 4);
                        if (state == "DS02") {
                            state = "('DS02','DS04','DS05','DS06','DS07','DS08','DS09','DS10')";
                        } else if (state == "DS01") {
                            state = "('DS01')";
                        } else if (state == "DS03") {
                            state = "('DS03')";
                        }
                        var container_no = $("#form_in_control_3").val();
                        var contract_no = $("#form_in_control_4").val();
                        var confirm_time_start = $("#form_in_control_5")
                                .val();
                        if (confirm_time_start != "") {
                            confirm_time_start = confirm_time_start
                                                 + " 00:00:00";
                        }
                        var confirm_time_end = $("#form_in_control_6")
                                .val();
                        if (confirm_time_end != "") {
                            confirm_time_end = confirm_time_end
                                               + " 23:59:59";
                        }
                        var company_name = $("#form_in_control_7").val();
                        var shipper_name = $("#form_in_control_8").val();
                        var url = "http://localhost:8075/WebReport/ReportServer?reportlet=supDeclarationList.cpt&businessId="
                                  // 	var url = "http://192.168.0.4:7080/report/ReportServer?reportlet=gtimp/supDeclarationList.cpt&businessId="
                                  + businessId
                                  + "&state="
                                  + state
                                  + "&container_no="
                                  + container_no
                                  + "&contract_no="
                                  + contract_no
                                  + "&company_name="
                                  + company_name
                                  + "&shipper_name="
                                  + shipper_name
                                  + "&confirm_time_start="
                                  + confirm_time_start
                                  + "&confirm_time_end="
                                  + confirm_time_end;//本机
                        window.open(url);
                    }
                },
                {
                    id: "customsPassDeclarationBtn",
                    value: "海关放行",
                    click: function () {
                        var selectedRowId = $("#declarationsDataGrid").jqGrid("getGridParam",
                                                                              "selarrrow");
                        if (selectedRowId.length > 0) {
                            $.ajax({
                                       type: "post",
                                       cache: false,
                                       url: "declaration-customsPassDeclaration?id="
                                            + selectedRowId,
                                       dataType: "json",
                                       success: function (data) {
                                           if ($.parseJSON(data.msg).state == 1) {
                                               jw.alert($.parseJSON(data.msg).msg);
                                               $("#declarationsDataGrid").jqGrid("setGridParam",
                                                                                 {
                                                                                     search: true
                                                                                     // 将jqGrid的search选项设为true
                                                                                 }).trigger(
                                                       "reloadGrid", [{
                                                           page: 1
                                                       }]);
                                           } else {
                                               jw.alert($.parseJSON(data.msg).msg);
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
// 						id : "customsPassDeclarationBtn",
// 						value : "海关放行",
// 						click : function() {
// 							var selectedRowId = $("#declarationsDataGrid")
// 									.getGridParam("selrow");
// 							if (selectedRowId) {
// 								var selectedRow = $("#declarationsDataGrid")
// 										.getRowData(selectedRowId);
// 								$
// 										.ajax({
// 											cache : false,
// 											url : "declaration-customsPassDeclaration?id="
// 													+ selectedRow.id,
// 											dataType : "json",
// 											success : function(data) {
// 												if ($.parseJSON(data.msg).state == 1) {
// 													jw
// 															.alert($
// 																	.parseJSON(data.msg).msg);
// 												} else {
// 													jw
// 															.alert($
// 																	.parseJSON(data.msg).msg);
// 												}
// 											}
// 										});
// 							} else {
// 								jw.alert("请点击需要操作的数据!");
// 							}
// 						}
                },
                {
                    id: "commodityInspectionBtn",
                    value: "商检放行",
                    click: function () {
                        var selectedRowId = $("#declarationsDataGrid").jqGrid("getGridParam",
                                                                              "selarrrow");
                        if (selectedRowId.length > 0) {
                            $.ajax({
                                       type: "post",
                                       cache: false,
                                       url: "declaration-commodityInspectionPass?id="
                                            + selectedRowId,
                                       dataType: "json",
                                       success: function (data) {
                                           if ($.parseJSON(data.msg).state == 1) {
                                               jw.alert($.parseJSON(data.msg).msg);
                                               $("#declarationsDataGrid").jqGrid("setGridParam",
                                                                                 {
                                                                                     search: true
                                                                                     // 将jqGrid的search选项设为true
                                                                                 }).trigger(
                                                       "reloadGrid", [{
                                                           page: 1
                                                       }]);
                                           } else {
                                               jw.alert($.parseJSON(data.msg).msg);
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "finishBtn",
                    value: "完成",
                    click: function () {
                        var selectedRowId = $("#declarationsDataGrid").jqGrid("getGridParam",
                                                                              "selarrrow");
                        if (selectedRowId.length > 0) {
                            $.ajax({
                                       type: "post",
                                       cache: false,
                                       url: "declaration-finishDeclarationPass?id=" + selectedRowId,
                                       dataType: "json",
                                       success: function (data) {
                                           if ($.parseJSON(data.msg).state == 1) {
                                               jw.alert($.parseJSON(data.msg).msg);
                                               $("#declarationsDataGrid").jqGrid("setGridParam",
                                                                                 {
                                                                                     search: true
                                                                                     // 将jqGrid的search选项设为true
                                                                                 }).trigger(
                                                       "reloadGrid", [{
                                                           page: 1
                                                       }]);
                                           } else {
                                               jw.alert($.parseJSON(data.msg).msg);
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "bindNumberBtn",
                    value: "绑定报关单号",
                    click: function () {
                        var selectedRowId = $("#declarationsDataGrid")
                                .getGridParam("selrow");
                        if (selectedRowId) {
                            // 								$.ajax({
                            // 									url : "declaration-bindingDeclarationNum?id="+selectedRow.id,
                            // 									dataType : "json",
                            // 									success : function(data) {

                            // 									}
                            // 								});
                            jw
                                    .dialog({
                                                iframe: "declaration-bindingDeclarationNum?id="
                                                        + selectedRowId,
                                                title: "绑定报关单号",
                                                iframeFetchTitle: false,
                                                width: 500,
                                                height: 150
                                            });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "updatebtn11",
                    value: "驳回业务",
                    click: function () {
                        var id = $("#declarationsDataGrid").jqGrid(
                                "getGridParam", "selrow");
                        if (id) {
                            var ret = $("#declarationsDataGrid").jqGrid(
                                    'getRowData', id);
                            var iddata = "id=" + ret.id + "&opType=bh";
                            $
                                    .ajax({
                                              cache: false,
                                              url: "declaration-checkValidatePass",
                                              dataType: "json",
                                              data: iddata,
                                              success: function (data) {
                                                  if ($.parseJSON(data.msg).state == 1) {
                                                      ajaxLoader
                                                              .ajaxPost(
                                                                      '../datalock/onUnlock?opaId=VDBS&bidId='
                                                                      + id,
                                                                      {},
                                                                      function (data) {
                                                                          if (!data) {
                                                                              jw
                                                                                      .alert(data.errmsg);
                                                                          }
                                                                          if ("200"
                                                                              == data.errcode) {
                                                                              jw
                                                                                      .dialog({
                                                                                                  iframe: '../business/rejectContent-reject?id='
                                                                                                          + id
                                                                                                          + "&type=1",
                                                                                                  title: "驳回",
                                                                                                  iframeFetchTitle: false,
                                                                                                  width: 500,
                                                                                                  height: 150
                                                                                              });
                                                                          } else {
                                                                              jw
                                                                                      .alert(data.errmsg);
                                                                          }
                                                                      });
                                                  } else if ($
                                                                     .parseJSON(data.msg).state
                                                             == 0) {
                                                      jw
                                                              .alert("只有处于待审核状态的业务才可以进行驳回业务操作。");
                                                  } else {
                                                      jw
                                                              .alert($
                                                                             .parseJSON(
                                                                                     data.msg).msg);
                                                  }
                                              }
                                          });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                }

                /* ,
                 {
                 id : "updatebtn2",
                 value : "业务数据上传",
                 click : function() {
                 var id = $("#declarationsDataGrid").jqGrid("getGridParam",
                 "selrow");
                 if(id) {
                 jw.confirm("确定要上传当前选择业务?",function(){
                 var ret = $("#declarationsDataGrid").jqGrid('getRowData',id);
                 var data = "id=" + ret.id;
                 $.ajax({
                 url : "declaration-validateUpload",
                 dataType : "json",
                 data : data,
                 success : function(data) {
                 jw.alert(data.msg);
                 $("#declarationsDataGrid").jqGrid("setGridParam",
                 {
                 search : true
                 // 将jqGrid的search选项设为true
                 }).trigger("reloadGrid", [ {
                 page : 1
                 } ]);
                 }
                 });
                 },
                 function(){return;});
                 } else {
                 jw.alert("请点击需要操作的数据!");
                 }
                 }
                 } */
            ]
        },
        grid: {
            id: "declarationsDataGrid",
            title: "查询结果",
            url: "declaration-findListForSupToValidate",
            rownumbers: true,
            multiselect: true,
            /* postData : {
             "pid" : pid
             }, */
            postData: {
                "declaraState": bstate
            },
            colModel: [{
                index: "ID",
                name: "id",
                hidden: true
            }, {
                index: "businessId",
                name: "businessId",
                label: "业务编号"
            }, {
                index: "work_no",
                name: "work_no",
                label: "流水号"
            }, {
                index: "container_no",
                name: "container_no",
                label: "集装箱号"
            }, {
                index: "contract_no",
                name: "contract_no",
                label: "合同协议号"
            }, {
                index: "company_name",
                name: "company_name",
                label: "经营单位"
            }, {
                index: "customerNAME",
                name: "customer.name",
                label: "业务委托人",
                hidden: true
            }, {
                index: "shipper",
                name: "shipper.company",
                label: "实际托运人"
            }, {
                index: "confirmTime",
                name: "confirmTime",
                label: "业务提交时间",
                formatter: 'date',
                formatoptions: {
                    srcformat: 'Y-m-d H:i:s',
                    newformat: 'Y-m-d H:i:s'
                }
            }, {
                index: "validateState",
                name: "decState",
                data: [["审核通过", "平台审核通过"], ["已申报", "已受理"], ["已完成", "DS05"], ["已申报", "初审"],
                    ["已申报", "复审"], ["已申报", "现场递单"], ["查验", "海关查验"],
                    ["海关放行", "DS10"], ["商检放行", "DS11"]],
                label: "业务状态"
            }, {
                index: "validator",
                name: "validator.name",
                label: "审核人"
            }, {
                index: "validateTime",
                name: "validateTime",
                label: "审核时间",
                formatter: 'date',
                formatoptions: {
                    srcformat: 'Y-m-d H:i:s',
                    newformat: 'Y-m-d H:i:s'
                }
            }, {
                index: "sno",
                name: "sno",
                label: "报关单号"
            }, {
                name: "upload",
                label: "底单上传"
            }, {
                index: "informState",
                name: "declarationInform.confirmState",
                label: "资料寄送提醒进度",
                hidden: true
            }, {
                index: "realSupId",
                name: "realSupId",
                label: "是否来自业务流转",
                hidden: true
            }, {
                index: "uploadDiDan",
                name: "uploadDiDan.id",
                label: "uploadDiDan",
                hidden: true
            }],
            // 			sortname: "businessId",
            sortname: "confirmTime",
            sortorder: "desc",
            // jsonReader: {
            //   root: "declarations"
            //},
            loadComplete: function (data) {
                var ids = $("#declarationsDataGrid").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                    var arrayData = $("#declarationsDataGrid").getRowData(
                            ids[i]);
                    if ($(arrayData).attr('declarationInform.confirmState') == "0") {
                        $("#declarationsDataGrid").setCell(ids[i],
                                                           "declarationInform.confirmState",
                                                           "已发送，待确认");
                    } else if ($(arrayData).attr(
                                    'declarationInform.confirmState') == "1") {
                        $("#declarationsDataGrid").setCell(ids[i],
                                                           "declarationInform.confirmState",
                                                           "已确认接收");
                        $($("#" + arrayData.id).find("td")[8]).addClass(
                                "biz_state_finish");
                    } else {
                        $("#declarationsDataGrid").setCell(ids[i],
                                                           "declarationInform.confirmState",
                                                           "客户未发送");
                    }

                    if (arrayData.realSupId == "") {
                        //$("#declarationsDataGrid").setCell(ids[i], "realSupId", "待确认");
                    } else {
                        var rsid = arrayData.realSupId.split(":")[0];
                        var fstate = arrayData.realSupId.split(":")[1];
                        $("#declarationsDataGrid").setCell(ids[i], "realSupId",
                                                           fstate);
                    }

                    //处理合同协议号默认值
                    if ($(arrayData).attr('contract_no') == "最长20个字符") {
                        $("#declarationsDataGrid").setCell(ids[i],
                                                           "contract_no", " ");
                    }

                    $("td[aria-describedby='declarationsDataGrid_decState']").each(function () {
                        if ($(this).text() == "平台审核通过") {
                            $(this).text("审核通过");
                        } else if ($(this).text() == "已受理" || $(this).text() == "初审"
                                   || $(this).text() == "复审" || $(this).text() == "现场递单") {
                            $(this).text("已申报");
                        } else if ($(this).text() == "海关查验") {
                            $(this).text("查验");
                        }
                    });

                    //底单上传链接
                    if ($(arrayData).attr('uploadDiDan.id') != "") {
                        $("#declarationsDataGrid")
                                .setCell(
                                        ids[i],
                                        "upload",
                                        "<div align='center'><a style='cursor:pointer;' id='upload_img_"
                                        + i + "' href='javascript:void(0)' onclick=\"upload(\'"
                                        + i
                                        + "\', 'upload', \'"
                                        + arrayData.id
                                        + "\');\"><font color='red'>底单已上传</font></a></div>");
                    } else {
                        $("#declarationsDataGrid")
                                .setCell(
                                        ids[i],
                                        "upload",
                                        "<div align='center'><a style='cursor:pointer;' id='upload_img_"
                                        + i + "' href='javascript:void(0)' onclick=\"upload(\'"
                                        + i
                                        + "\', 'upload', \'"
                                        + arrayData.id
                                        + "\');\"><font color='red'>底单未上传</font></a></div>");
                    }

                }
            },
            ondblClickRow: function () {

                var selectedRowId = $("#declarationsDataGrid").getGridParam(
                        "selrow");
                if (selectedRowId) {
                    var selectedRow = $("#declarationsDataGrid").getRowData(
                            selectedRowId);
                    ajaxLoader
                            .ajaxPost(
                                    '../datalock/onUnlock?opaId=VDBS&bidId='
                                    + selectedRow.id,
                                    {},
                                    function (data) {
                                        if (!data) {
                                            jw.alert(data.errmsg);
                                        }
                                        if ("200" == data.errcode) {
                                            if (selectedRow.state == "草稿状态") {
                                                //selectedRow.busiId
                                                location.href = "business-updateSingle?id="
                                                                + selectedRow.id
                                                                + "&singleType=D";
                                            } else {
                                                location.href = "business-updateSingle?id="
                                                                + selectedRow.id
                                                                + "&singleType=D&identification=list";
                                            }
                                        } else {
                                            jw.alert(data.errmsg);
                                        }
                                    });
                }
            }
        }
    };
    $(document).ready(function () {
        $("#declarationsDataTable").mrdForm(formSetting);
    });

    function upload(i, colName, bizId) {
        jw.dialog({
                      iframe: 'declaration-uploadDiDan?id=' + bizId,
                      width: 800, height: 300
                  });
    }
</script>
<body>
<div id="declarationsDataTable"></div>
</body>
</html>
